package com.java.zhuiyun.api.sys_menu.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.java.zhuiyun.api.sys_icon.entity.Icon;
import com.java.zhuiyun.api.sys_icon.mapper.IconMapper;
import com.java.zhuiyun.api.sys_menu.entity.Menu;
import com.java.zhuiyun.api.sys_menu.mapper.MenuMapper;
import com.java.zhuiyun.api.sys_menu.service.IMenuService;
import com.java.zhuiyun.common.response.CommonConstants;
import com.java.zhuiyun.common.response.CommonResult;
import com.java.zhuiyun.util.pageUtil.PageRequest;
import org.apache.ibatis.annotations.Param;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @ClassName MenuController
 * @Description TODO
 * @Author xy
 * @Date 2023/8/16 16:27
 **/
@RestController
@RequestMapping("/Menu")
public class MenuController {

    @Resource
    IMenuService menuService;

    @Resource
    IconMapper iconMapper;

    @Resource
    MenuMapper menuMapper;

    /**
     * @Author xy
     * @Description 全查
     * @Date 2023/8/15 18:50
     * @Return  * @param null
     */
    @GetMapping("/MenuList")
    public CommonResult MenuList(){
        return CommonResult.ok(menuService.MenuList());
    }

    /**
     * @Author xy
     * @Description 添加
     * @Date 2023/8/15 20:14
     * @Return  * @param null
     */
    @PostMapping("/MenuAdd")
    public CommonResult MenuAdd(@RequestBody Menu menu){
        int i = menuService.MenuAdd(menu);
        if (i>0){
            return CommonResult.ok("恭喜您，添加成功");
        }else {
            return CommonResult.error("很抱歉，添加失败");
        }
    }

    /**
     * @Author xy
     * @Description 修改
     * @Date 2023/8/15 16:26
     * @Return  * @param null
     */
    @PostMapping("/MenuUpdate")
    public CommonResult MenuUpdate(@RequestBody Menu menu){
        int i = menuService.MenuUpdate(menu);
        if (i>0){
            return CommonResult.ok("恭喜您，修改成功");
        }else {
            return CommonResult.error("很抱歉，修改失败");
        }
    }

    /**
     * @Author xy
     * @Description 修改目录
     * @Date 2023/8/15 16:26
     * @Return  * @param null
     */
    @PostMapping("/updateml")
    public CommonResult updateml(@RequestBody Menu menu){
        int i = menuService.updateml(menu);
        if (i>0){
            return CommonResult.ok("恭喜您，修改成功");
        }else {
            return CommonResult.error("很抱歉，修改失败");
        }
    }

    /**
     * @Author xy
     * @Description 逻辑删除
     * @Date 2023/8/15 16:41
     * @Return  * @param null
     */
    @DeleteMapping("/MenuDelete")
    public CommonResult MenuDelete(Integer id){
        int i = menuService.MenuDelete(id);
        if (i>0){
            return CommonResult.ok("恭喜您，删除成功");
        }else {
            return CommonResult.error("很抱歉，删除失败");
        }
    }

    @GetMapping("/icons")
    public CommonResult getIcons() {
        List<Icon> list = iconMapper.IconList();
        return CommonResult.ok(list);
    }

    @GetMapping("/findAll")
    public CommonResult findAll(@RequestParam(defaultValue = "") String mname) {
        return CommonResult.ok(menuService.findMenus(mname));
    }

    @GetMapping("/ids")
    public CommonResult findAllIds() {
        return CommonResult.ok(menuMapper.selectList().stream().map(Menu::getId));
    }
}
